package myJs.user.workflow.featureSelection.preprocess

import myJs.myPkg.reactHookForm.UseFormRT
import myJs.tool.Tool.messages
import shared.Pojo.FsPreprocessData
import shared.pojo.WorkflowMission.{ExtraData, FsData}

import scala.collection.immutable.SeqMap
import com.softwaremill.quicklens._

import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._
import cats.effect._
import myJs.Implicits._

/** Created by yz on 21/1/2022
  */
object Cp {

  case class Props(
      fsData: FsData,
      fsDataChange:  FsData => SyncIO[Unit],
      showIdStr: String,
      extraData: ExtraData
  ){
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>
    object FTool {

      def preprocessChange = (preProcessData: FsPreprocessData) => {
        val modifyF = props.fsData.modify(_.preprocess).setTo(preProcessData)
        props.fsDataChange(modifyF)
      }

    }

    val displayMod =
      if (props.showIdStr == props.fsData.preprocess.nodeId) display.block else display.none

    div(
      className := "myArg",
      displayMod,
      PreprocessCp.Props(
        preProcess = props.fsData.preprocess,
        preProcessChange = FTool.preprocessChange,
        extraData = props.extraData
      ).render
    )

  }

}
